using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace ICP_MS.Plugin.Tune;

public class FormResolution : Form
{
	public List<Resolution> resolutions = new List<Resolution>();

	public Resolution Resolution = new Resolution
	{
		ResolutionType = 1,
		LowLimit = 0.6,
		HighLimit = 0.8
	};

	public string path = Application.StartupPath + "//iMassConfig//Resolutions.xml";

	private IContainer components = null;

	private TextBox textBox1;

	private Label label1;

	private TextBox textBox2;

	private TextBox textBox3;

	private TextBox textBox4;

	private Label label2;

	private TextBox textBox5;

	private TextBox textBox6;

	private Label label3;

	private RadioButton rdbtnHigh;

	private RadioButton rdbtnStandard;

	private RadioButton rdbtnLow;

	private Button button1;

	private Button button2;

	public FormResolution()
	{
		InitializeComponent();
	}

	private void textBox1_TextChanged(object sender, EventArgs e)
	{
	}

	private void FormResolution_Load(object sender, EventArgs e)
	{
		if (!XMLFile.Open(path, ref resolutions) || resolutions == null || resolutions.Count == 0)
		{
			resolutions.Clear();
			resolutions.Add(new Resolution
			{
				ResolutionType = 1,
				LowLimit = 0.6,
				HighLimit = 0.8
			});
			resolutions.Add(new Resolution
			{
				ResolutionType = 0,
				LowLimit = 0.3,
				HighLimit = 0.5
			});
			resolutions.Add(new Resolution
			{
				ResolutionType = 2,
				LowLimit = 0.8,
				HighLimit = 1.0
			});
		}
		textBox1.Text = resolutions.Find((Resolution r) => r.ResolutionType == 0).LowLimit.ToString();
		textBox2.Text = resolutions.Find((Resolution r) => r.ResolutionType == 0).HighLimit.ToString();
		textBox3.Text = resolutions.Find((Resolution r) => r.ResolutionType == 1).LowLimit.ToString();
		textBox4.Text = resolutions.Find((Resolution r) => r.ResolutionType == 1).HighLimit.ToString();
		textBox5.Text = resolutions.Find((Resolution r) => r.ResolutionType == 2).LowLimit.ToString();
		textBox6.Text = resolutions.Find((Resolution r) => r.ResolutionType == 2).HighLimit.ToString();
		ApplyResources();
	}

	private void ApplyResources()
	{
		Text = Lang.Txt("FormResolution.Set");
		rdbtnHigh.Text = Lang.Txt("FormResolution.High");
		rdbtnStandard.Text = Lang.Txt("FormResolution.Standard");
		rdbtnLow.Text = Lang.Txt("FormResolution.Low");
		button1.Text = Lang.Txt("FormSerial.OK");
		button2.Text = Lang.Txt("FormSerial.Cancel");
	}

	private void button1_Click(object sender, EventArgs e)
	{
		try
		{
			if (rdbtnHigh.Checked)
			{
				Resolution.ResolutionType = 0;
				Resolution.LowLimit = double.Parse(textBox1.Text);
				Resolution.HighLimit = double.Parse(textBox2.Text);
			}
			if (rdbtnStandard.Checked)
			{
				Resolution.ResolutionType = 1;
				Resolution.LowLimit = double.Parse(textBox3.Text);
				Resolution.HighLimit = double.Parse(textBox4.Text);
			}
			if (rdbtnLow.Checked)
			{
				Resolution.ResolutionType = 2;
				Resolution.LowLimit = double.Parse(textBox5.Text);
				Resolution.HighLimit = double.Parse(textBox6.Text);
			}
			Resolution res = resolutions.Find((Resolution r) => r.ResolutionType == Resolution.ResolutionType);
			if (res != null)
			{
				res.LowLimit = Resolution.LowLimit;
				res.HighLimit = Resolution.HighLimit;
			}
			XMLFile.Save(path, resolutions);
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
			return;
		}
		base.DialogResult = DialogResult.OK;
	}

	private void button2_Click(object sender, EventArgs e)
	{
		base.DialogResult = DialogResult.Cancel;
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.textBox1 = new System.Windows.Forms.TextBox();
		this.label1 = new System.Windows.Forms.Label();
		this.textBox2 = new System.Windows.Forms.TextBox();
		this.textBox3 = new System.Windows.Forms.TextBox();
		this.textBox4 = new System.Windows.Forms.TextBox();
		this.label2 = new System.Windows.Forms.Label();
		this.textBox5 = new System.Windows.Forms.TextBox();
		this.textBox6 = new System.Windows.Forms.TextBox();
		this.label3 = new System.Windows.Forms.Label();
		this.rdbtnHigh = new System.Windows.Forms.RadioButton();
		this.rdbtnStandard = new System.Windows.Forms.RadioButton();
		this.rdbtnLow = new System.Windows.Forms.RadioButton();
		this.button1 = new System.Windows.Forms.Button();
		this.button2 = new System.Windows.Forms.Button();
		base.SuspendLayout();
		this.textBox1.Location = new System.Drawing.Point(200, 44);
		this.textBox1.Name = "textBox1";
		this.textBox1.Size = new System.Drawing.Size(100, 25);
		this.textBox1.TabIndex = 1;
		this.textBox1.Text = "0.3";
		this.textBox1.TextChanged += new System.EventHandler(textBox1_TextChanged);
		this.label1.AutoSize = true;
		this.label1.Location = new System.Drawing.Point(306, 50);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(15, 15);
		this.label1.TabIndex = 2;
		this.label1.Text = "-";
		this.textBox2.Location = new System.Drawing.Point(330, 44);
		this.textBox2.Name = "textBox2";
		this.textBox2.Size = new System.Drawing.Size(100, 25);
		this.textBox2.TabIndex = 1;
		this.textBox2.Text = "0.5";
		this.textBox3.Location = new System.Drawing.Point(200, 93);
		this.textBox3.Name = "textBox3";
		this.textBox3.Size = new System.Drawing.Size(100, 25);
		this.textBox3.TabIndex = 1;
		this.textBox3.Text = "0.6";
		this.textBox4.Location = new System.Drawing.Point(330, 93);
		this.textBox4.Name = "textBox4";
		this.textBox4.Size = new System.Drawing.Size(100, 25);
		this.textBox4.TabIndex = 1;
		this.textBox4.Text = "0.8";
		this.label2.AutoSize = true;
		this.label2.Location = new System.Drawing.Point(306, 98);
		this.label2.Name = "label2";
		this.label2.Size = new System.Drawing.Size(15, 15);
		this.label2.TabIndex = 2;
		this.label2.Text = "-";
		this.textBox5.Location = new System.Drawing.Point(200, 141);
		this.textBox5.Name = "textBox5";
		this.textBox5.Size = new System.Drawing.Size(100, 25);
		this.textBox5.TabIndex = 1;
		this.textBox5.Text = "0.8";
		this.textBox6.Location = new System.Drawing.Point(330, 143);
		this.textBox6.Name = "textBox6";
		this.textBox6.Size = new System.Drawing.Size(100, 25);
		this.textBox6.TabIndex = 1;
		this.textBox6.Text = "1.0";
		this.label3.AutoSize = true;
		this.label3.Location = new System.Drawing.Point(306, 146);
		this.label3.Name = "label3";
		this.label3.Size = new System.Drawing.Size(15, 15);
		this.label3.TabIndex = 2;
		this.label3.Text = "-";
		this.rdbtnHigh.AutoSize = true;
		this.rdbtnHigh.Location = new System.Drawing.Point(49, 50);
		this.rdbtnHigh.Name = "rdbtnHigh";
		this.rdbtnHigh.Size = new System.Drawing.Size(88, 19);
		this.rdbtnHigh.TabIndex = 3;
		this.rdbtnHigh.Text = "高分辨率";
		this.rdbtnHigh.UseVisualStyleBackColor = true;
		this.rdbtnStandard.AutoSize = true;
		this.rdbtnStandard.Checked = true;
		this.rdbtnStandard.Location = new System.Drawing.Point(49, 94);
		this.rdbtnStandard.Name = "rdbtnStandard";
		this.rdbtnStandard.Size = new System.Drawing.Size(103, 19);
		this.rdbtnStandard.TabIndex = 3;
		this.rdbtnStandard.TabStop = true;
		this.rdbtnStandard.Text = "标准分辨率";
		this.rdbtnStandard.UseVisualStyleBackColor = true;
		this.rdbtnLow.AutoSize = true;
		this.rdbtnLow.Location = new System.Drawing.Point(49, 142);
		this.rdbtnLow.Name = "rdbtnLow";
		this.rdbtnLow.Size = new System.Drawing.Size(88, 19);
		this.rdbtnLow.TabIndex = 3;
		this.rdbtnLow.Text = "低分辨率";
		this.rdbtnLow.UseVisualStyleBackColor = true;
		this.button1.Location = new System.Drawing.Point(225, 193);
		this.button1.Name = "button1";
		this.button1.Size = new System.Drawing.Size(75, 23);
		this.button1.TabIndex = 4;
		this.button1.Text = "确定";
		this.button1.UseVisualStyleBackColor = true;
		this.button1.Click += new System.EventHandler(button1_Click);
		this.button2.Location = new System.Drawing.Point(330, 193);
		this.button2.Name = "button2";
		this.button2.Size = new System.Drawing.Size(75, 23);
		this.button2.TabIndex = 4;
		this.button2.Text = "取消";
		this.button2.UseVisualStyleBackColor = true;
		this.button2.Click += new System.EventHandler(button2_Click);
		base.AutoScaleDimensions = new System.Drawing.SizeF(8f, 15f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(457, 239);
		base.Controls.Add(this.button2);
		base.Controls.Add(this.button1);
		base.Controls.Add(this.rdbtnLow);
		base.Controls.Add(this.rdbtnStandard);
		base.Controls.Add(this.rdbtnHigh);
		base.Controls.Add(this.label3);
		base.Controls.Add(this.label2);
		base.Controls.Add(this.label1);
		base.Controls.Add(this.textBox6);
		base.Controls.Add(this.textBox4);
		base.Controls.Add(this.textBox2);
		base.Controls.Add(this.textBox5);
		base.Controls.Add(this.textBox3);
		base.Controls.Add(this.textBox1);
		base.Name = "FormResolution";
		this.Text = "分辨率设置";
		base.Load += new System.EventHandler(FormResolution_Load);
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
